use std::path::PathBuf;
// use crate::generic_func::{add, show2};
use crate::generic_func::{add, largest};
use crate::generic_struct::Response;
use crate::generic_trait::{Book, ShowBook};

mod generic_func;
mod generic_struct;
mod generic_trait;

// Rust 语言中的泛型主要包含 泛型集合、泛型结构体、泛型函数、范型枚举 和 特质 。
fn main() {
    // generic_collect();
    // generic_struct();
    // generic_trait();
    // 泛型函数，有错误，暂无法调试通过
    // generic_func();
    // println!("{}",largest_u32(1,2));
    match std::env::home_dir() {
        None => {println!("option is none ")}
        Some(dir) => {
            println!("option is some ,data = {:?}",dir)
        }
    }
}

fn largest_u32(a: u32, b: u32) -> u32 {
    if a > b {
        a
    } else {
        b
    }
}

fn generic_func() {
    let number_list = vec![34, 50, 25, 100, 65];
    let result = largest(&number_list);
    println!("The largest number is {}", result);

    let char_list = vec!['y', 'm', 'a', 'q'];
    let result = largest(&char_list);
    println!("The largest char is {}", result);

    println!("{}", add(4, 5));
}

fn generic_trait() {
    let book = Book {
        isbn: String::from("111-22-3333"),
        name: String::from("Rust 权威指南"),
        author: String::from("Unknown"),
    };
    book.show()
}

fn generic_collect() {
    let mut v: Vec<i32> = vec![1, 2, 3];
    // 成功，4 是 i32 类型
    v.push(4);
    // 失败，"5"不是 i32 类型
    // v.push("5");
    println!("{:?}", v);
}

fn generic_struct() {
    let r: Response<i32> = Response {
        code: 200,
        message: String::from("OK"),
        data: 66,
    };
    println!("data:{}", r.data);

    let r: Response<String> = Response {
        code: 200,
        message: String::from("OK"),
        data: String::from("Hello World"),
    };
    println!("data:{}", r.data);

    // let rect = Rectange { width: 3, height: 5 };
    // let ar = rect.area();
    // println!("{}",ar);
}
